package scauCmiScaffolding.compiled;

import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.RuntimeTagElement;
import org.eclipse.jet.taglib.TagInfo;

public class _jet_cmiPagination_2 implements JET2Template {
    private static final String _jetns_c = "org.eclipse.jet.controlTags"; //$NON-NLS-1$

    public _jet_cmiPagination_2() {
        super();
    }

    private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
    
    private static final TagInfo _td_c_get_1_9 = new TagInfo("c:get", //$NON-NLS-1$
            1, 9,
            new String[] {
                "select", //$NON-NLS-1$
            },
            new String[] {
                "$packageName", //$NON-NLS-1$
            } );
    private static final TagInfo _td_c_get_10_8 = new TagInfo("c:get", //$NON-NLS-1$
            10, 8,
            new String[] {
                "select", //$NON-NLS-1$
            },
            new String[] {
                "$packageName", //$NON-NLS-1$
            } );
    private static final TagInfo _td_c_iterate_43_6 = new TagInfo("c:iterate", //$NON-NLS-1$
            43, 6,
            new String[] {
                "var", //$NON-NLS-1$
                "select", //$NON-NLS-1$
            },
            new String[] {
                "eachTable", //$NON-NLS-1$
                "$table", //$NON-NLS-1$
            } );
    private static final TagInfo _td_c_if_44_4 = new TagInfo("c:if", //$NON-NLS-1$
            44, 4,
            new String[] {
                "test", //$NON-NLS-1$
            },
            new String[] {
                "$eachTable/@isRelation='false'", //$NON-NLS-1$
            } );
    private static final TagInfo _td_c_get_45_28 = new TagInfo("c:get", //$NON-NLS-1$
            45, 28,
            new String[] {
                "select", //$NON-NLS-1$
            },
            new String[] {
                "lowercaseFirst($eachTable/@name)", //$NON-NLS-1$
            } );

    public void generate(final JET2Context context, final JET2Writer __out) {
        JET2Writer out = __out;
        out.write("package ");  //$NON-NLS-1$        
        RuntimeTagElement _jettag_c_get_1_9 = context.getTagFactory().createRuntimeTag(_jetns_c, "get", "c:get", _td_c_get_1_9); //$NON-NLS-1$ //$NON-NLS-2$
        _jettag_c_get_1_9.setRuntimeParent(null);
        _jettag_c_get_1_9.setTagInfo(_td_c_get_1_9);
        _jettag_c_get_1_9.doStart(context, out);
        _jettag_c_get_1_9.doEnd();
        out.write(".util;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write(NL);         
        out.write("import java.lang.reflect.Field;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.util.Collection;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.util.HashMap;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.util.Map;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.util.function.BiConsumer;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("import ");  //$NON-NLS-1$        
        RuntimeTagElement _jettag_c_get_10_8 = context.getTagFactory().createRuntimeTag(_jetns_c, "get", "c:get", _td_c_get_10_8); //$NON-NLS-1$ //$NON-NLS-2$
        _jettag_c_get_10_8.setRuntimeParent(null);
        _jettag_c_get_10_8.setTagInfo(_td_c_get_10_8);
        _jettag_c_get_10_8.doStart(context, out);
        _jettag_c_get_10_8.doEnd();
        out.write(".util.CmiHibernateProxyUtil;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("public class CmiPagination {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    private String name;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    private int paginationSize;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    private int beginPage;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    private int currentPagination;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    private int totalPaginations;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    private int totalRecords;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    Map<String, CmiAttributePagination> attributeMap;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public CmiPagination() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this(5, 1, 1, 1, 0);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    ");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    public CmiPagination(Object object) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this(5, 1, 1, 1, 0);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.setPage(object);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public CmiPagination(int paginationSize, int beginPage, int currentPagination, int totalPaginations, int totalRecords) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        super();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.paginationSize = paginationSize;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.beginPage = beginPage;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.currentPagination = currentPagination;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.totalPaginations = totalPaginations;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.totalRecords = totalRecords;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.attributeMap = new HashMap<String, CmiAttributePagination>();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("//        initAttribute();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    private void initAttribute() {");  //$NON-NLS-1$        
        out.write(NL);         
        RuntimeTagElement _jettag_c_iterate_43_6 = context.getTagFactory().createRuntimeTag(_jetns_c, "iterate", "c:iterate", _td_c_iterate_43_6); //$NON-NLS-1$ //$NON-NLS-2$
        _jettag_c_iterate_43_6.setRuntimeParent(null);
        _jettag_c_iterate_43_6.setTagInfo(_td_c_iterate_43_6);
        _jettag_c_iterate_43_6.doStart(context, out);
        while (_jettag_c_iterate_43_6.okToProcessBody()) {
            RuntimeTagElement _jettag_c_if_44_4 = context.getTagFactory().createRuntimeTag(_jetns_c, "if", "c:if", _td_c_if_44_4); //$NON-NLS-1$ //$NON-NLS-2$
            _jettag_c_if_44_4.setRuntimeParent(_jettag_c_iterate_43_6);
            _jettag_c_if_44_4.setTagInfo(_td_c_if_44_4);
            _jettag_c_if_44_4.doStart(context, out);
            while (_jettag_c_if_44_4.okToProcessBody()) {
                out.write("\t\t\t\tthis.attributeMap.put(\"");  //$NON-NLS-1$        
                RuntimeTagElement _jettag_c_get_45_28 = context.getTagFactory().createRuntimeTag(_jetns_c, "get", "c:get", _td_c_get_45_28); //$NON-NLS-1$ //$NON-NLS-2$
                _jettag_c_get_45_28.setRuntimeParent(_jettag_c_if_44_4);
                _jettag_c_get_45_28.setTagInfo(_td_c_get_45_28);
                _jettag_c_get_45_28.doStart(context, out);
                _jettag_c_get_45_28.doEnd();
                out.write("s\", new CmiAttributePagination());");  //$NON-NLS-1$        
                out.write(NL);         
                _jettag_c_if_44_4.handleBodyContent(out);
            }
            _jettag_c_if_44_4.doEnd();
            _jettag_c_iterate_43_6.handleBodyContent(out);
        }
        _jettag_c_iterate_43_6.doEnd();
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    /**");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("     * 传入集合实例，获取集合大小，设置实例继承的page");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("     * 传入单个实例，获取其类型为集合的成员，得到集合大小，设置实例继承的page(设置总页数目和所有记录数目)");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("     * ");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("     * @param object");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("     */");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    public void setPage(Object object) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        // TODO");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        if (object instanceof Collection<?>) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            int myTotalRecords = ((Collection<?>) object).size();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            this.setTotalRecords(myTotalRecords);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            int myTotalPages = 0;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            if (myTotalRecords % this.paginationSize == 0) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                myTotalPages = myTotalRecords / this.paginationSize;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            } else {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                myTotalPages = myTotalRecords / this.paginationSize + 1;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            this.setTotalPages(myTotalPages);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        } else {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            object = CmiHibernateProxyUtil.deproxy(object);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            Field[] fields = object.getClass().getDeclaredFields();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            Field.setAccessible(fields, true);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            for (Field field : fields) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                Object fieldObject;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                try {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    String fieldName = field.getName();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    fieldObject = field.get(object);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    if (!(fieldObject instanceof Collection<?>))");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                        continue;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    ");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    if (!this.attributeMap.containsKey(fieldName)) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\t\t\t// 是集合就注册 CmiAttributePagination");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\t\t\tthis.attributeMap.put(fieldName, new CmiAttributePagination());");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\t\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\t\t@SuppressWarnings(\"unchecked\")");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    Collection<Object> objCollection = (Collection<Object>) fieldObject;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("                    int myTotalRecords = objCollection.size();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("//                    System.out.println(\"---------\" + fieldName);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    CmiAttributePagination cmiAttributePagination = this.attributeMap.get(fieldName);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("                    cmiAttributePagination.setTotalRecords(myTotalRecords);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    int myTotalPages = 0;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    if (myTotalRecords % cmiAttributePagination.paginationSize == 0) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                        myTotalPages = myTotalRecords / cmiAttributePagination.paginationSize;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    } else {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                        myTotalPages = myTotalRecords / cmiAttributePagination.paginationSize + 1;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    cmiAttributePagination.setTotalPages(myTotalPages);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                } catch (IllegalArgumentException | IllegalAccessException e) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    // TODO Auto-generated catch block");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                    e.printStackTrace();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("            }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public String getName() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return name;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public void setName(String name) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.name = name;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public int getPageSize() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return paginationSize;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public void setPageSize(int paginationSize) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.paginationSize = paginationSize;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public int getBeginPage() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return beginPage;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public void setBeginPage(int beginPage) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.beginPage = beginPage;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public int getCurrentPage() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return currentPagination;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public void setCurrentPage(int currentPagination) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.currentPagination = currentPagination;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public int getTotalPages() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return totalPaginations;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public void setTotalPages(int totalPaginations) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.totalPaginations = totalPaginations;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public int getTotalRecords() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return totalRecords;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public void setTotalRecords(int totalRecords) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.totalRecords = totalRecords;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public Map<String, CmiAttributePagination> getAttributeMap() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return attributeMap;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    public void setAttributeMap(Map<String, CmiAttributePagination> attribute) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        this.attributeMap = attribute;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("    @Override");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    public String toString() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("        return \"CmiPagination [name=\" + name + \", paginationSize=\" + paginationSize + \", beginPage=\" + beginPage + \", currentPagination=\"");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                + currentPagination + \", totalPaginations=\" + totalPaginations + \", totalRecords=\" + totalRecords + \", attributeMap=\"");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("                + attributeMap + \"]\";");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("    }");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("}");  //$NON-NLS-1$        
        out.write(NL);         
    }
}
